<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/all.conf.php');
require_once(__PHY_LIB.'/inc/page.user.inc.php');

$rReq = validate($_REQUEST, 'action:e[edit,update]');
$sMsg = false;

if ('update' == $rReq['action']) {
	do {
		$oUser = new uUser($_The['User']['id']);
		$rP = validate($_POST, 'nick:u');
		$oTpl->assign('rP', $rP);
		if (!$rP['nick']) { $sMsg .= "没有昵称。"; $rReq['action'] = 'edit'; break; }
		foreach ($rP as $sField => $xValue) {
			$oUser->set($sField, $xValue);
		}
		if ($oUser->update()) {
			$_The['User'] = $oUser->getData();
			$sMsg .= '修改成功。'; $rReq['action'] = 'edit'; break;
		}
		else {
			$sMsg .= '修改失败。'; $rReq['action'] = 'edit'; break;
		}
	} while (false);
}

if ('edit' == $rReq['action']) {
	$oTpl->assign('rMe', $_The['User']);
}

$oTpl->assign('sMsg', $sMsg);
$oTpl->assign('sAction', $rReq['action']);
$oTpl->display(dirname(__FILE__).'/'.basename(__FILE__, '.php').'.tpl');
?>
